package com.example.administrator.szb.util;

import android.support.v7.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import com.example.administrator.szb.activity.HomeActivity;

import cn.jpush.im.android.api.JMessageClient;

/**
 * Created by stone on 2018/1/16.
 */

public class LogoutDialog {
    static AlertDialog  alertDialog;


    public static void showDialog(final Context context,String str){
        JMessageClient.logout();//极光退出登录
        SPUtils.clear();
        SPUtils.setDatas(SPUtils.IS_LOADED_YDY,1);
        alertDialog = new AlertDialog.Builder(context)
                .setTitle("账号异常")
                .setCancelable(false)
                .setMessage(str)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        alertDialog.dismiss();
                        alertDialog=null;
                        logouts(context);
                    }
                })
                .show();
    }
    private static void logouts(Context context){

        JMessageClient.logout();//极光退出登录
        SPUtils.clear();
        SPUtils.setDatas(SPUtils.IS_LOADED_YDY,1);
        FinishActivity.finish();
        Intent intent = new Intent(context,HomeActivity.class);
        context.startActivity(intent);
    }
}
